#-*- coding:utf-8 -*-
'''
Created on 2012-8-16

@author: johnny
'''
import platform
import os

#Just one shot
def ping(ip):
    if not ip:
        return
    
    if platform.system() == 'Linux':
        cmd = "ping -c 1 %s" % ip
        print "ping: pinging %s ......" % ip
        if os.system(cmd):
            return False        
    elif platform.system() == 'Windows':
        cmd = 'ping -n 1 %s' % ip
        print "pinging %s ......" % ip
        reply = os.popen(cmd).readlines()
        for s in reply:
            s = s.decode('gbk')
            if s.find("无法访问") >= 0 or s.find("Ureachable") >= 0:
                return False
    return True


if __name__ == "__main__":
    print ping("192.168.200.10")